const service = require("../services/etymology");

class Controller {
	async list(req, res) {
		try {
			const body = await service.list(req.query);
			res.json(body);
		} catch (err) {
			res.json({
				code: 500,
				message: "error",
				result: {},
			});
		}
	}
	async getEtymologyByTypeAndKeyword(req, res) {
		try {
			const body = await service.getEtymologyByTypeAndKeyword(req.query);
			res.json(body);
		} catch (err) {
			res.json({
				code: 500,
				message: "error",
				result: {},
			});
		}
	}

	async getEtymologyDetailById(req, res) {
		try {
			const body = await service.getEtymologyDetailById(req.query);
			res.json(body);
		} catch (err) {
			res.json({
				code: 500,
				message: "error",
				result: {},
			});
		}
	}

	async add(req, res) {
		try {
			const body = await service.add(req.body);
			res.json(body);
		} catch (err) {
			res.json({
				code: 500,
				message: "error",
				result: {},
			});
		}
	}

	async update(req, res) {
		try {
			const body = await service.update(req.body);
			res.json(body);
		} catch (err) {
			res.json({
				code: 500,
				message: "error",
				result: {},
			});
		}
	}

	async del(req, res) {
		try {
			const body = await service.del(req.body.id);
			res.json(body);
		} catch (err) {
			res.json({
				code: 500,
				message: "error",
				result: {},
			});
		}
	}

	async upload(req, res) {
		try {
			const body = await service.upload(req, res);
			res.json(body);
		} catch (err) {
			res.json({
				code: 500,
				message: "error",
				result: {},
			});
		}
	}
}

module.exports = new Controller();
